import sys
import warnings
import json
warnings.filterwarnings("ignore")

from dejavu import Dejavu
from dejavu.recognize import FileRecognizer

config_path = "./conf/dejavu.conf"

def init(configpath):
    """ 
    Load config from a JSON file
    """
    try:
        with open(configpath) as f:
            config = json.load(f)
    except IOError as err:
        print("Cannot open configuration: %s. Exiting" % (str(err)))
        sys.exit(1)

    # create a Dejavu instance
    return Dejavu(config)

djv = init(config_path)
print "Recognizing... Please wait a moment..."
song = djv.recognize(FileRecognizer, "./data/wav/current.wav")
print "========================================"
print "From file we recognized:\n %s\n" % song
